/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.service.utils.scheduled;

import java.util.Date;
import java.util.Timer;

/**
 *
 * @author ECH
 */
public class TSMockDSServices {
    
    private Timer backupServiceTimer = new Timer();
    private boolean backupServiceRunning = false;
    private Date backupServiceStartDate;
    private long backupServiceInterval;
    
    private TKSaveDS taskSaveDS = new TKSaveDS();
    
    public void startBackupService(Date startDate, long interval) { 
        try {
            if (!isBackupServiceRunning()) {
                backupServiceTimer = new Timer();
                taskSaveDS = new TKSaveDS();
                backupServiceTimer.scheduleAtFixedRate(taskSaveDS, startDate, interval);
                
                this.setBackupServiceStartDate(startDate);
                this.setBackupServiceInterval(interval);
                this.setBackupServiceRunning(true); 
            }            
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    public void stopBackupService() {     
        try {   
            backupServiceTimer.cancel();
            backupServiceTimer.purge();
            setBackupServiceRunning(false);
        } catch (Exception ex) {}
    }

    public boolean isBackupServiceRunning() {
        return backupServiceRunning;
    }

    public void setBackupServiceRunning(boolean backupServiceRunning) {
        this.backupServiceRunning = backupServiceRunning;
    }

    public Date getBackupServiceStartDate() {
        return backupServiceStartDate;
    }

    public void setBackupServiceStartDate(Date backupServiceStartDate) {
        this.backupServiceStartDate = backupServiceStartDate;
    }

    public long getBackupServiceInterval() {
        return backupServiceInterval;
    }

    public void setBackupServiceInterval(long backupServiceInterval) {
        this.backupServiceInterval = backupServiceInterval;
    }
}
